<template>
  <div class="search-filter-bar" :isShow="show" :class="{'fixed':fixed, 'hasFilter':hasFilter}">
    <input type="text" placeholder="搜索" class="search-input" :class="{'full': !showCancel}" v-model="searchVal" />
    <span class="cancel-btn" @click="cancel" v-if="showCancel">取消</span>
  </div>
</template>
<script>
  export default {
    props: {
      hasFilter: {
        default: true
      },
      fixed: {
        default: true
      },
      showCancel: {
        default: false
      },
      value: {
      }
    },
    data () {
      return {
        show: false,
        searchVal: ''
      }
    },
    methods: {
      cancel () {
        this.$emit('cancel')
      }
    },
    watch: {
      searchVal (value) {
        this.$emit('search-change', value)
      }
    },
    mounted () {
      this.searchVal = this.value
      this.$emit('show')
    }

  }
</script>
<style lang="less">
  @import '../less/index.less';

  .search-filter-bar {
    top:0;

    &:not(.fixed) {
      position: absolute;
    }

    &.fixed {
      position: fixed;
    }

    &.hasFilter {
      top: @top-filter-size
    }

    left:0;
    z-index: 102;
    width: 100%;
    padding-top: @search-input-padding;
    padding-bottom: @search-input-padding;
    background-color: white;
    border: 1px solid #EDEDED;
    white-space: nowrap;
    overflow: hidden;
    -webkit-user-select:none;
    -moz-user-select:none;
    -ms-user-select:none;
    user-select:none;
  }

  .search-input {
    width: 86%;
    float: left;
    height: @search-input-size;
    line-height: @search-input-size;
    // margin: 0 auto;
    margin-left: 2px;
    text-indent: 1em;
    font-size: 14px;
    -webkit-appearance:none;
    border-radius: 0;
    border: 1px solid #EDEDED;
    display: block;
    // float: left;

    &.full {
      float: none;
      margin: 0 auto;
      width: 96%;
    }
  }

  .cancel-btn {
    // padding: 0 6px;
    margin: 0;
    // border: 1px solid #EDEDED;
    height: @search-input-size;
    line-height: @search-input-size;
    width: 10%;
    border-radius: 2px;
    float: right;
    margin-right:6px;
    color: #35ADFF;
    text-align: center;
  }
</style>
